package com.atguigu.flink.chapter02_DataStreamAPI.multistream;

import org.apache.flink.streaming.api.datastream.ConnectedStreams;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.co.CoMapFunction;

/**
 * Created by Smexy on 2022/10/22
 *
 *      连接。不是合并。
 *            Union  春秋时期，秦国吞并六国，合为一体。
 *            Connect  美国是多个州联合在一起。
 *                          同床异梦
 *                          泾渭分明
 */
public class Demo8_Connect
{
    public static void main(String[] args) {

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<Integer> ds1 = env.fromElements(1, 2, 3, 4, 5);
        DataStreamSource<String> ds3 = env.fromElements("a", "b", "c");

        ConnectedStreams<Integer, String> ds4 = ds1.connect(ds3);
        ds4
            .map(new CoMapFunction<Integer, String, String>()
            {
                //xxx.connect(yyy)
                //处理第一个流xxx
                @Override
                public String map1(Integer value) throws Exception {
                    return value + "是数字";
                }

                //处理第二个流，连接的那个流  yyyy
                @Override
                public String map2(String value) throws Exception {
                    return value + "是字符串";
                }
            })
            .print();

        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
